package cn.egame.extraction.multithread.service.filter2;

import cn.egame.common.exception.ExceptionCommonBase;

public class ApplicationFilterChain implements FilterChain {
	private Filter[] filters = 
			        new Filter[0];

	private int n = 0;
	private int pos = 0;
	
	public static final int INCREMENT = 10;

	
	@Override
	public void doFilter(ChainObject chainObject) throws ExceptionCommonBase {
		if(pos < n){
			Filter filter = filters[pos++];
			filter.doFilter(chainObject, this);
		}
	}

	@Override
	public void addFilter(Filter filter) {
		if(n==filters.length){
			Filter[] newFilters =
					new Filter[n + INCREMENT];
			System.arraycopy(filters, 0, newFilters, 0, n);
			filters = newFilters;
		}
		filters[n++] = filter;
	}

}
